<?php
class Pageley_Gateway_Database_Condition_AggregateSqlDecorator extends Pageley_Gateway_Database_Condition_AbstractSqlDecorator {
	private $decoratedConditions;
    
	public function __construct($decoratedCondition, $query) {
		parent::__construct($decoratedCondition);
		$this->decoratedConditions = new Pageley_Util_ArrayMap();
		foreach($decoratedCondition->getConditions() as $condition) {
			$this->decoratedConditions->add($this->decorateCondition($condition, $query));
		}
	}
	
	protected function createSql() {
		$sql = "( ";
		$first = true;
		foreach($this->decoratedConditions as $condition) {
			if($first === true) {
				$first = false;
			} else {
				$sql .= " " . $this->getOperator() . " ";
			}
			$sql .= $condition->toSql();
		}
		$sql .= " )";
		return $sql;
	}
    
    public function getFromClause() {
        $sql = "";
        foreach($this->decoratedConditions as $condition) {
            $sql .= $condition->getFromClause();
        }
        return $sql;;
    }
	
    public function getValues() {
        $values = new Pageley_Util_ArrayMap();
        foreach($this->decoratedConditions as $condition) {
            $values->putAll($condition->getValues());
        }
        return $values;
    }
}